package yagwl.server.fnd;

import java.util.logging.Logger;

import yagwl.service.util.svc.Context;

public class RestApiFilter extends AbstractFilter {

  private static Logger log = Logger.getLogger(RestApiFilter.class.getName());

  @Override
  protected boolean isSenderAuthorized() {
    log.fine("Skipping authorization for now");
    if (true) // TODO P4 enable sender authorization when ready
      return true;
    log.fine("Authorizing");
    String authHdr = request.getHeader("Authorization");
    if (authHdr == null)
      return false;
    String[] parts = authHdr.split(" ", 2);
    if (parts.length < 2)
      return false;
    String authScheme = parts[0].trim();
    String authCredentials = parts[1].trim();
    log.fine(authScheme + " " + authCredentials);

    if (authScheme == null || !authScheme.equals("MTEP")
        || authCredentials == null)
      return false;
    return true;
  }

  @Override
  protected boolean isUserLoggingOut(Context ctx) {
    // TODO Auto-generated method stub
    return false;
  }

  @Override
  protected boolean isUserLoggingIn(Context ctx) {
    // TODO Auto-generated method stub
    return false;
  }

  @Override
  protected boolean isUserLoggedIn(Context ctx) {
    // TODO Auto-generated method stub
    return false;
  }

  @Override
  protected void setUserIdInContext(Context ctx) {
    // TODO Auto-generated method stub
    
  }

  @Override
  protected void setEmailInContext(Context ctx) {
    // TODO Auto-generated method stub
    
  }

  @Override
  protected void setNicknameInContext(Context ctx) {
    // TODO Auto-generated method stub
    
  }

  @Override
  protected boolean isUserIdMismatch(Context ctx) {
    // TODO Auto-generated method stub
    return false;
  }

  @Override
  protected boolean isRequestAuthorized() {
    return true;
  }

}